package com.yan.test;

import com.google.common.collect.ImmutableList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by yanl_ on 2018/3/9.
 */
public class ExecutorUtils {

    public void test() {
        ImmutableList<String> list = ImmutableList.of("a", "b", "c", "d");
        ExecutorService executorService = Executors.newCachedThreadPool();

        for (int i = 0; i < list.size(); i++) {
            final int id = i;
            String value = list.get(i);
            final Map<Integer, String> map = new HashMap<Integer, String>();
            map.put(id, value);
            executorService.execute(new Runnable() {
                public void run() {
                    test2(id, map);
                }
            });

        }
    }

    public void test2(int i, Map<Integer, String> map) {

        System.out.println(i + "  " + map);
    }

    public static void main(String[] args) {

        new ExecutorUtils().test();
    }

}
